#include <cstdio>
#include <cstring>

int main( )
{
    char data[ 1001 ];
    int i, t;
    while ( scanf("%s", data) != EOF )
    {
        t = 0;
        for ( i = 0; i < strlen( data ); i++ )
        {
            if ( data[ i ] == 'B' )
                break;
            if ( data[ i ] == '(' )
                t++;
            if ( data[ i ] == ')' )
                t--;
        }
        printf("%d\n", t);
    }
    return 0;
}
